/*
 * This source code is part of TWaver 4.0
 *
 * Serva Software PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 * Copyright 2002 - 2011 Serva Software. All rights reserved.
 */

package demo.sheet.inherit;

import java.awt.BorderLayout;
import java.awt.Color;

import javax.swing.JSplitPane;

import twaver.Element;
import twaver.MovableFilter;
import twaver.ResizableNode;
import twaver.TDataBox;
import twaver.TWaverConst;
import twaver.TWaverUtil;
import twaver.network.TNetwork;
import twaver.table.Category;
import twaver.table.TPropertySheet;
import twaver.table.TPropertySheetPane;
import demo.DemoPane;

public class InheritPropertyDemo extends DemoPane {
	
	public InheritPropertyDemo(){
		Category.registerCategory("commonness", "Commonness");
		Category.registerCategory("individuality", "Individuality");
		Category.registerCategory("extension", "Extension");
		
		TWaverUtil.registerBeanInfoWithoutDefault(TWaver0.class);
		TWaverUtil.registerBeanInfo(TWaver0.class, "/demo/sheet/inherit/TWaver0.xml");
		TWaverUtil.registerBeanInfo(TWaver1.class, "/demo/sheet/inherit/TWaver1.xml");
		TWaverUtil.registerBeanInfo(TWaver2.class, "/demo/sheet/inherit/TWaver2.xml");
		TWaverUtil.registerBeanInfo(TWaver3.class, "/demo/sheet/inherit/TWaver3.xml");
		
		TDataBox box = new TDataBox();
		TNetwork network = new TNetwork(box);
		TPropertySheet sheet = new TPropertySheet(box);
		network.setColorBackground(new Color(0, 255, 255));
		network.addMovableFilter(new MovableFilter(){
			public boolean isMovable(Element element) {
				return false;
			}
		});
		sheet.setEditable(false);		
		
		Class[] classes = new Class[]{TWaver0.class, TWaver1.class, TWaver2.class, TWaver3.class};
		Color[] colors = new Color[]{Color.RED, Color.MAGENTA, Color.GREEN, Color.BLUE};
		for(int i=0; i<classes.length; i++){
			try {
				Class clazz = classes[i];
				ResizableNode element = (ResizableNode)clazz.newInstance();
				element.setName("TWaver " + element.getClientProperty("version"));
				element.setSize(120 + i * 50, 40);
				element.setCenterLocation(230, 85 + 80 * i);
				element.putLabelColor(colors[i]);
				element.putLabelPosition(TWaverConst.POSITION_CENTER);
				element.putCustomDraw(true);
				element.putCustomDrawShapeFactory(TWaverConst.SHAPE_ROUND_RECTANGLE);
				element.putCustomDrawGradientFactory(TWaverConst.GRADIENT_EXTEND_N);
				element.putCustomDrawFillColor(new Color(0, 0, 51));
				box.addElement(element);
				
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		
    	JSplitPane split = new JSplitPane();
    	split.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
    	split.setContinuousLayout(true);
    	split.setOneTouchExpandable(true);
    	split.add(network, JSplitPane.LEFT);
    	split.add(new TPropertySheetPane(sheet), JSplitPane.RIGHT);
    	split.setDividerLocation(500);
        this.add(split, BorderLayout.CENTER);
	}

}